package com.zxy.supplier_system.server.service

import com.zxy.supplier_system.server.controller.MarketShoppingGuideSalaryPlanResultController
import com.zxy.supplier_system.server.repository.MarketShoppingGuideSalaryPlanResultRepository
import com.zxy.supplier_system.server.utils.orElse404
import org.springframework.stereotype.Service

@Service
class MarketShoppingGuideSalaryPlanResultService(
    private val marketShoppingGuideSalaryPlanResultRepository: MarketShoppingGuideSalaryPlanResultRepository,
    private val systemServiceService: SystemServiceService
) {

    fun getCopiedPlan(
        id: Int,
        year: Int,
        month: Int
    ): MarketShoppingGuideSalaryPlanResultController.MarketShoppingGuideSalaryPlanResultPlanResponse {
        val marketShoppingGuideSalaryPlanResult = marketShoppingGuideSalaryPlanResultRepository.findByMarket_SystemServiceAndMarket_IdAndYearAndMonth(
            systemServiceService.getCurrentSystemService(),
            id, year, month
        ).orElse404()
        return MarketShoppingGuideSalaryPlanResultController.MarketShoppingGuideSalaryPlanResultPlanResponse(
            marketShoppingGuideSalaryPlanResult.minimumSalary,
            marketShoppingGuideSalaryPlanResult.rules,
        )
    }

}